#include "addfriend.h"
#include "ui_addfriend.h"
#include <QTcpSocket>


AddFriend::AddFriend(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AddFriend)
{
    ui->setupUi(this);
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(SendSlot()));
}

void AddFriend::SetSocket(QTcpSocket *s,QString u)
{
    this->socket = s;
    username = u;
}

AddFriend::~AddFriend()
{
    delete ui;
}

void AddFriend::SendSlot()
{
//    GetMsg getmsg;
//    getmsg.cmd = CMD_GET_MSG_ADDFRIEND;
//    strcpy(getmsg.username,username.toStdString().c_str());
//    socket->write((const char *)&getmsg,MSG_LENGTH);
    ChatPackage pack;
    pack.cmd = CMD_CHAT_TO_FRIEND;
    //qDebug()<<pack.from;
    sprintf(pack.from,username.toStdString().c_str());
    sprintf(pack.to,ui->lineEdit->text().toStdString().c_str());
    sprintf(pack.msgbody,"addfrined");
    socket->write((const char *)&pack,MSG_LENGTH);
    this->close();

}
